package wks.reflect;

import wks.service.TestService;
import wks.service.impl.TestServiceImpl;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class JdkReflect {
    public static void main(String[] args) {
        final TestService service = new TestServiceImpl();
        TestService proxyInstance = (TestService) Proxy.newProxyInstance(JdkReflect.class.getClassLoader(), service.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("我套你猴子");
                Object invoke = method.invoke(service, args);
                System.out.println("啊里呀噶痛");
                return invoke;
            }
        });
        String s = proxyInstance.doSomeThing();
        proxyInstance.doAnyThing(s);

        Map<String,String> map = new HashMap<>(3);
        map.put("600519","贵州茅台");
        map.put("601398","工商银行");
        map.put("300750","宁德时代");
        List<Object> list1 = map.entrySet().stream().map(ent -> ent.getKey()+":"+ent.getValue()).collect(Collectors.toList());
        List<Object> list2 = map.entrySet().stream().map(ent -> ent.getKey()).collect(Collectors.toList());
        List<Object> list3 = map.entrySet().stream().map(ent -> ent.getValue()).collect(Collectors.toList());
        list1.forEach(listFor -> System.out.println(listFor));
        System.out.println("map数据格式:" + map);
        System.out.println("list数据格式:" + list1);


    }
}
